#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include "bounded_vector.h"

using namespace std;

class char_counter
{
private:
	bounded_vector doc1;
	bounded_vector doc2;

public:

	char_counter()
	{
		doc1.set_bounds('a', 'z');
		doc2.set_bounds('a', 'z');
	}

	~char_counter()
	{
	}

	void read_files(string file_one, string file_two)
	{
		string row;
		try
		{
			ifstream fin(file_one);
			while (!fin.eof())
			{
				char c;
				fin >> c;
				if (c >= 'A' && c <= 'Z')
					doc1[c + 32]++;
				else if (c >= 'a' && c <= 'z')
					doc1[c]++;
			}
			fin.close();
			fin.open(file_two);
			while (!fin.eof())
			{
				char c;
				fin >> c;
				if (c >= 'A' && c <= 'Z')
					doc2[c + 32]++;
				else if (c >= 'a' && c <= 'z')
					doc2[c]++;
			}
			fin.close();
		}
		catch (exception e)
		{
			cout << e.what() << endl;
		}
	}

	void print()
	{
		cout << "Character count:" << endl;
		for (char c = 'a'; c <= 'z'; c++)
			cout << c << ": " << doc1[c] - doc2[c] << " , " << doc1[c] << " , " << doc2[c] << endl;

		int sum1 = doc1.total_sum();
		int sum2 = doc2.total_sum();

		cout << endl <<  "Character promille:" << endl;
		for (char c = 'a'; c <= 'z'; c++)
		{
			int doc1_p = (doc1[c] * 1000) / sum1;
			int doc2_p = (doc2[c] * 1000) / sum2;
			cout << c << ": " << doc1_p - doc2_p << " , " << doc1_p << " , " << doc2_p << endl;
		}
	}

};

